#!/usr/bin/perl -w

# Read the magic number
if(defined($line = <STDIN>)) {
	if($line eq "LINK") {
		print "Magic Number Wrong\n";
		return;
	}
}

# Read the number of segments, symbols and relocations
my ($nsegs,$nsyms, $nrels) = (0,0,0);
if(defined($line = <STDIN>)) {
	if ($line =~ /(\w+)\s+(\w+)\s+(\w+)/) {
		$nsegs = $1;
		$nsyms = $2;
		$nrels = $3;
	}
}

# Read information about each segment
for(my $i=0; $i<$nsegs; $i++) {
	if(defined($line = <STDIN>)) {
		push @segs, [split(/\s+/, $line)];
	}
}

# Read information about each symbols
for(my $i=0; $i<$nsyms; $i++) {
	if(defined($line = <STDIN>)) {
		push @syms, [split(/\s+/, $line)];
	}
}

# Read information about each segments
for(my $i=0; $i<$nrels; $i++) {
	if(defined($line = <STDIN>)) {
		push @rels, [split(/\s+/, $line)];
	}
}

print "Segments:\n";
for(my $i=0; $i<$nsegs; $i++) {
	print "$i : $segs[$i][0]  $segs[$i][1] $segs[$i][2] $segs[$i][3]\n";
}
print "Symbols:\n";
for(my $i=0; $i<$nsyms; $i++) {
	print "$i : $syms[$i][0]  $syms[$i][1] $syms[$i][2] $syms[$i][3]\n";
}
print "Relocations:\n";
for(my $i=0; $i<$nrels; $i++) {
	print "$i : $rels[$i][0]  $rels[$i][1] $rels[$i][2] $rels[$i][3]\n";
}
